<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Http\Requests;
use DB;
use App\Http\Controllers\Controller;

class AdminsController extends Controller
{
	//管理前台用户列表
    public function getIndex(Request $request)
    {	
    	//读取数据并且分页
    	$member=DB::table('member')
    	->where(function($query)use($request){
    		$query->where('user','like','%'.$request->input('keywords').'%');
    	})
		->paginate($request->input('num',10));
    	// dd($users);
    	return view('admin.member.index',['member'=>$member,'request'=>$request->all()]);
    }
    //
    // 修改前台用户信息 编辑页
    public function getEdit($id)
    {	
    	//根据传过来的ID查询用户信息
    	$res=DB::table('member')->where('id',$id)->first();
    	return view('admin.member.edit',['member'=>$res]);
    }

    //修改前台用户信息
    public function postUpdate(Request $request)
    {
    	//接收信息执行修改
    	$date=$request->only(['qian','email']);
    	$id=$request->input('id');

    	$res=DB::table('member')->where('id',$id)->update($date);
    	if($res){
    		return redirect('/admin/member/index')->with('success','数据修改成功');
    	}else{
    		return back()->with('error','数据修改失败');
    	}
    }

    public function getDelete($id)
    {
    	$res=DB::table('member')->where('id',$id)->delete();
    	if($res){
    		return redirect('/admin/member/index')->with('success','数据删除成功');
    	}else{
    		return back()->with('error','数据删除失败');
    	}
    }
}
